﻿using System;
using Sunny.UI;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ClassLibrary;
using ClassLibrary.Service;

namespace Forms
{
    public partial class MyMessagebox : UIUserControl
    {
        User Sender = new User();//每个消息发送者对应一个消息框
        User Receiver = new User();//消息接收者为当前主界面的用户
        InteractionService IS = new InteractionService();
        public MyMessagebox(User Sender, User Receiver)
        {
            InitializeComponent();
            this.Sender = Sender;
            this.Receiver = Receiver;
            NameLabel.Text = Sender.UserName;

            List<Interaction> interactions = new List<Interaction>();//消息列表
            interactions = IS.GetCurrentInteractionBySenderAndReceiver(Sender, Receiver);//返回按时间排序的消息
            if (interactions[0].InteractionContent != null)
            {
                MessageLabel.Text = interactions[0].InteractionContent;//显示最新消息的内容和时间
            }
            else
            {
                MessageLabel.Text = "[动画表情]";
            }
            TimeLabel.Text = interactions[0].InteractionTime.ToString();
            pictureBox1.Image = ImageService.BytesToImage(ImageService.getProfileByID(Sender.UserID));
        }

        private void NameLabel_Click(object sender, EventArgs e)
        {

        }

        private void MyMessagebox_Click(object sender, EventArgs e)
        {

        }

        private void uiButton1_Click(object sender, EventArgs e)
        {
            try
            {
                ChatForm cf = new ChatForm(Receiver, Sender);
                cf.ShowDialog();
            }
            catch (Exception ex)
            {
                UIMessageBox.Show($"Error: {ex.Message}");
            }
        }

        private void uiImageButton1_Click(object sender, EventArgs e)
        {
            try
            {
                ProfileForm profileForm = new ProfileForm(Sender, pictureBox1.Image, Receiver);
                profileForm.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Error: {ex.Message}");
            }
        }

        private void TimeLabel_Click(object sender, EventArgs e)
        {

        }
    }
}
